package operators;

import java.util.Scanner;

public class ScannerWithOperators {
    public static void main(String[] args) {
        // 创建Scanner对象，用于读取用户输入
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入第一个整数: ");
        int num1 = scanner.nextInt();

        System.out.print("请输入第二个整数: ");
        int num2 = scanner.nextInt();

        // 使用算术操作符
        int sum = num1 + num2;
        int difference = num1 - num2;
        int product = num1 * num2;
        double quotient = (double) num1 / num2;  // 强制转换为double以得到精确结果
        int remainder = num1 % num2;

        System.out.println("\n算术运算结果:");
        System.out.println(num1 + " + " + num2 + " = " + sum);
        System.out.println(num1 + " - " + num2 + " = " + difference);
        System.out.println(num1 + " * " + num2 + " = " + product);
        System.out.println(num1 + " / " + num2 + " = " + quotient);
        System.out.println(num1 + " % " + num2 + " = " + remainder);

        // 使用关系操作符
        System.out.println("\n关系运算结果:");
        System.out.println(num1 + " == " + num2 + " : " + (num1 == num2));
        System.out.println(num1 + " > " + num2 + " : " + (num1 > num2));
        System.out.println(num1 + " <= " + num2 + " : " + (num1 <= num2));

        // 使用逻辑操作符
        System.out.println("\n逻辑运算结果:");
        System.out.println("两个数都大于0 : " + (num1 > 0 && num2 > 0));
        System.out.println("至少有一个数是偶数 : " + (num1 % 2 == 0 || num2 % 2 == 0));

        // 使用三元操作符
        String maxStr = (num1 > num2) ? num1 + " 更大" : num2 + " 更大";
        System.out.println("\n" + maxStr);

        // 关闭Scanner
        scanner.close();
    }
}
